which converts a tmstruct in UTC to a time_t.
strncpy(secString, currentMark->created+13, 2);
secString[2] = '\0';
t.tm_sec = atoi(secString);
- currentMark->wp->creation_time = mktime(&t) + get_tz_offset();
+ currentMark->wp->creation_time = mkgmtime(&t);
}
}
else if (inRoute) {
tm.tm_year -= 1900;
tm.tm_isdst = 0;
- rv = mktime(&tm) + get_tz_offset() - off_sign*off_hr*3600 -
- off_sign*off_min*60;
+ rv = mkgmtime(&tm) - off_sign*off_hr*3600 - off_sign*off_min*60;
xfree(timestr);
tm.tm_year -= 1900;
tm.tm_isdst = 0;
- utc = mktime(&tm) + get_tz_offset() ;
+ utc = mkgmtime(&tm);
wpt_tmp->creation_time = utc;
}
tm.tm_year += 100;
}
tm.tm_isdst = 0;
- creation = mktime(&tm) + get_tz_offset();
+ creation = mkgmtime(&tm);
// Create a route to store the task data in.
rte_head = route_head_alloc();
tm.tm_year += 100;
}
tm.tm_isdst = 0;
- date = mktime(&tm) + get_tz_offset();
+ date = mkgmtime(&tm);
} else {
// Store other header data in the track descriptions
if (strlen(trk_desc) < MAXDESCLEN) {
dmy = dmy / 100;
tm.tm_mday = dmy % 100;
- waypt->creation_time = mktime(&tm) + get_tz_offset();
+ waypt->creation_time = mkgmtime(&tm);
waypt->centiseconds = fracsecs;
if (latdir == 'S') latdeg = -latdeg;
tm.tm_mon = dmy % 100 - 1;
dmy = dmy / 100;
tm.tm_mday = dmy;
- creation_time = mktime(&tm) + get_tz_offset();
+ creation_time = mkgmtime(&tm);
if (posn_type == gpgga)
return;
tm.tm_mday = dd;
tm.tm_mon = mm - 1;
tm.tm_year = yy - 1900;
- creation_time = mktime(&tm) + get_tz_offset();
+ creation_time = mkgmtime(&tm);
}
static void
int ckval, ckcmp;
struct tm tm;
- creation_time = mktime(&tm) + get_tz_offset() + current_time();
+ creation_time = mkgmtime(&tm) + current_time();
while (fgets(ibuf, sizeof(ibuf), file_in)) {
ck = strrchr(ibuf, '*');
{
tm.tm_year -= 1900;
tm.tm_mon--;
- wpt_tmp->creation_time = mktime(&tm) + get_tz_offset();
+ wpt_tmp->creation_time = mkgmtime(&tm);
}
break;
case 5:
tm.tm_mon = month_lookup(month);
tm.tm_year = atoi(date + 7) + 100;
wpt_tmp = waypt_new();
- wpt_tmp->creation_time = mktime(&tm) + get_tz_offset();
+ wpt_tmp->creation_time = mkgmtime(&tm);
wpt_tmp->latitude = lat;
wpt_tmp->longitude = lon;
wpt_tmp->altitude = alt;
&(tmTime.tm_sec));
tmTime.tm_isdst = 0;
- dateTime = mktime(&tmTime) + get_tz_offset();
+ dateTime = mkgmtime(&tmTime);
psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), whitespace);
/*
* Return a time_t suitable for adding to a time_t that is in GMT to
* make it a local time.
+ * Obsolete: to use mkgmtime instead.
*/
signed int
get_tz_offset(void)
}
}
+/*
+ mkgmtime -- convert tm struct in UTC to time_t
+
+ works just like mktime but without all the mucking
+ around with timezones and daylight savings
+
+ obsoletes get_tz_offset()
+
+ Borrowed from lynx GPL source code
+ http://lynx.isc.org/release/lynx2-8-5/src/mktime.c
+
+ Written by Philippe De Muyter <phdm@macqel.be>.
+*/
+
+time_t
+mkgmtime(struct tm *t)
+{
+ short month, year;
+ time_t result;
+ static int m_to_d[12] =
+ {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
+
+ month = t->tm_mon;
+ year = t->tm_year + month / 12 + 1900;
+ month %= 12;
+ if (month < 0)
+ {
+ year -= 1;
+ month += 12;
+ }
+ result = (year - 1970) * 365 + m_to_d[month];
+ if (month <= 1)
+ year -= 1;
+ result += (year - 1968) / 4;
+ result -= (year - 1900) / 100;
+ result += (year - 1600) / 400;
+ result += t->tm_mday;
+ result -= 1;
+ result *= 24;
+ result += t->tm_hour;
+ result *= 60;
+ result += t->tm_min;
+ result *= 60;
+ result += t->tm_sec;
+ return(result);
+}
+
+
/*
* A wrapper for time(2) that allows us to "freeze" time for testing.
*/
tmStruct.tm_sec =(int)floor(seconds);
tmStruct.tm_isdst =-1;
- wpt_tmp->creation_time = mktime(&tmStruct) + get_tz_offset();
+ wpt_tmp->creation_time = mkgmtime(&tmStruct);
wpt_tmp->centiseconds = fmod(100*seconds+0.5,100);
snprintf(shortname, sizeof shortname-1 , "WP%04d", ++serial);